import React, { useState } from 'react';
import { Button } from "./ui/button";
import { Dialog, DialogContent, DialogTrigger, DialogTitle } from "./ui/dialog";
import { useLanguage } from "~/lib/LanguageContext";
import AIChatStream from './ai-chat-stream';

interface MainAIChatProps {
  repoUrl?: string;
}

export default function MainAIChat({ repoUrl }: MainAIChatProps) {
  const { t } = useLanguage();
  const [isOpen, setIsOpen] = useState(false);

  // Don't render the chat button if no repoUrl is provided
  if (!repoUrl) {
    return null;
  }
  
  return (
    <Dialog open={isOpen} onOpenChange={setIsOpen}>
      <DialogTrigger asChild>
        <Button
          className="border-[3px] mt-4 border-black bg-blue-400 px-4 py-2 text-black shadow-[4px_4px_0_0_#000000] transition-transform hover:-translate-x-0.5 hover:-translate-y-0.5 hover:bg-blue-300 dark:border-gray-700 dark:bg-blue-600 dark:text-white dark:shadow-[4px_4px_0_0_#1f1f1f] dark:hover:bg-blue-500"
          size="lg"
        >
          {t("ai_chat")}
        </Button>
      </DialogTrigger>
      <DialogContent className="max-w-3xl h-[70vh] p-0" hideCloseButton>
        <DialogTitle className="sr-only">{t("ai_chat")}</DialogTitle>
        <AIChatStream 
          repoUrl={repoUrl}
          onClose={() => setIsOpen(false)}
        />
      </DialogContent>
    </Dialog>
  );
} 